package com.inforich.web.controller.tourist;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.inforich.common.annotation.Log;
import com.inforich.common.core.controller.BaseController;
import com.inforich.common.core.domain.AjaxResult;
import com.inforich.common.enums.BusinessType;
import com.inforich.common.utils.poi.ExcelUtil;
import com.inforich.tourist.domain.Carousel;
import com.inforich.tourist.service.ICarouselService;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * carouselController
 *
 * @author hjm
 * @date 2022-10-21
 */
@RestController
@RequestMapping("/tourist/carousel")
public class CarouselController extends BaseController {

  @Autowired
  private ICarouselService carouselService;

  /**
   * 查询carousel列表
   */
  @PreAuthorize("@ss.hasPermi('tourist:carousel:list')")
  @GetMapping("/list")
  public Page<Carousel> list(Page<Carousel> page, Carousel carousel) {
    Map<String, Object> map = beanToMap(carousel);
    carouselService.pageCarousel(page, map);
    return page;
  }


  /**
   * 导出carousel列表
   */
  @PreAuthorize("@ss.hasPermi('tourist:carousel:export')")
  @Log(title = "carousel", businessType = BusinessType.EXPORT)
  @PostMapping("/export")
  public void export(HttpServletResponse response, Carousel carousel) {
    Map<String, Object> map = beanToMap(carousel);
    List<Carousel> list = carouselService.listCarousel(map);
    ExcelUtil<Carousel> util = new ExcelUtil<Carousel>(Carousel.class);
    util.exportExcel(response, list, "carousel数据");
  }

  /**
   * 获取carousel详细信息
   */
  @PreAuthorize("@ss.hasPermi('tourist:carousel:query')")
  @GetMapping(value = "/{id}")
  public AjaxResult getInfo(@PathVariable("id") String id) {
    return AjaxResult.success(carouselService.getById(id));
  }

  /**
   * 新增carousel
   */
  @PreAuthorize("@ss.hasPermi('tourist:carousel:add')")
  @Log(title = "carousel", businessType = BusinessType.INSERT)
  @PostMapping
  public AjaxResult add(@Validated @RequestBody Carousel carousel) {
    return toAjax(carouselService.save(carousel));
  }

  /**
   * 修改carousel
   */
  @PreAuthorize("@ss.hasPermi('tourist:carousel:edit')")
  @Log(title = "carousel", businessType = BusinessType.UPDATE)
  @PutMapping
  public AjaxResult edit(@Validated @RequestBody Carousel carousel) {
    return toAjax(carouselService.updateById(carousel));
  }

  /**
   * 删除carousel
   */
  @PreAuthorize("@ss.hasPermi('tourist:carousel:remove')")
  @Log(title = "carousel", businessType = BusinessType.DELETE)
  @DeleteMapping("/{ids}")
  public AjaxResult remove(@PathVariable String[] ids) {
    return toAjax(carouselService.removeByIds(Arrays.asList(ids)));
  }
}
